package com.kedacom.freedomLabel.base;

import android.content.Context;
import android.os.Environment;
import android.support.annotation.IntDef;

import com.seray.scaleviewlib.utils.CacheDiskStaticUtils;

import java.io.File;

/**
 * 秤系统基本配置类
 */
public class AppConfig {

    public static final String MATTER = "Matter";

    public static final String DB_NAME = "SHJ-Burdening.db";

    public static final String BATCH = "Batch";

    public static String DB_PATH;

    public static String LOCAL_PATH;

    public static void init(Context context) {
        LOCAL_PATH = Environment.getExternalStorageDirectory()
                + File.separator + context.getPackageName() + File.separator;

        DB_PATH = LOCAL_PATH + "database" + File.separator;

        // 删除老版本数据
        String OLD_LOCAL_PATH = Environment.getExternalStorageDirectory()
                + File.separator + "infol"
                + File.separator;

//        FileIOUtils.deleteFile(OLD_LOCAL_PATH);
    }

    /**
     * 秤系统的类型
     */
    public static int SCALE_TYPE = ScaleType.SR200;

    /**
     * 是否是地秤
     */
    public static boolean isT200() {
        SCALE_TYPE = getScaleTypeFromDb();
        return SCALE_TYPE == ScaleType.T200;
    }

    /**
     * 是否是桌秤
     */
    public static boolean isSR200() {
        SCALE_TYPE = getScaleTypeFromDb();
        return SCALE_TYPE == ScaleType.SR200;
    }

    /**
     * 从数据库中取出秤类型
     *
     * @return 默认类型：T200
     */
    private static int getScaleTypeFromDb() {
        String type = CacheDiskStaticUtils.getString(ScaleType.class.getSimpleName(), String.valueOf(ScaleType.SR200));
        return Integer.parseInt(type);
    }

    /**
     * 将秤类型保存至数据库
     */
    public static void saveScaleTypeToDb() {
        CacheDiskStaticUtils.put(ScaleType.class.getSimpleName(), String.valueOf(SCALE_TYPE));
    }

    @IntDef({
            ScaleType.T200,
            ScaleType.SR200
    })
    public @interface ScaleType {
        int T200 = 0;
        int SR200 = 1;
    }
}
